package com.example.myshixun.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myshixun.R;
import com.squareup.picasso.Picasso;

import java.util.List;

public class FoodListAdapter extends BaseAdapter {
    List list;
    Context context;
    public FoodListAdapter(List<FoodListBean> list,Context context){
        this.list = list;
        this.context = context;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.food,parent,false);
        TextView tvName = view.findViewById(R.id.food_name);
        TextView tvprice = view.findViewById(R.id.food_price);
        ImageView imageView = view.findViewById(R.id.iv_food);
        FoodListBean.ListBean listBean = (FoodListBean.ListBean) list.get(position);

        tvName.setText(listBean.getName());
        tvprice.setText(listBean.getPrice()+"元");
        Picasso.with(context)
                .load("http://192.168.66.126:8080/18/statics/"+listBean.getIcon())
                .into(imageView);
        return view;
    }
}
